package vv.lines.core;

import vv.lines.core.context.IContext;
import vv.lines.view.View;

import java.util.Collection;

import static vv.lines.utils.LinesConstants.BUSY;

/**
 *
 * @author vpotapenko
 */
public class Cell extends AbstractFieldItem {

    private final int column;
    private final int row;

    private int value = 0;
    private Ball ball;

    private Collection<Cell> peers;

    public Cell(IContext context, int column, int row) {
        super(context);

        this.column = column;
        this.row = row;

        createView();
    }

    public Ball getBall() {
        return ball;
    }

    public void setBall(Ball ball) {
        this.ball = ball;
    }

    public Collection<Cell> getPeers() {
        return peers;
    }

    public void setPeers(Collection<Cell> peers) {
        this.peers = peers;
    }

    public int getColumn() {
        return column;
    }

    public int getRow() {
        return row;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    public void generateInitValue() {
        value = ball != null ? BUSY : 0;
    }

    @Override
    protected View createView() {
        return getViewFactory().createCellView(this);
    }

    public void handleAction(ActionId type) {
        getField().dispatchCellSelection(this);
    }
}
